<?php
/**
 * ============================================================================
 * 版权所有 多多科技，保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/

if(!defined('INDEX')){
	exit('Access Denied');
}
function act_goods_index2($ajax_load_num=4){
	global $duoduo;
	$webset=$duoduo->webset;
	define('VIEW_PAGE',1);
	$goods_total=1;
	if(isset($_GET['code'])&&$_GET['code']){
		$bankuai_code=$_GET['code'];
		$bankuai_cache=dd_get_cache('bankuai');
		$bankuai=$bankuai_cache[$bankuai_code];
		$bankuai_title=$bankuai['title'];
		$web_cid=unserialize($bankuai['web_cid']);
		$bankuai_id=(int)$bankuai['id'];
		$bankuai_tpl=$bankuai['bankuai_tpl'];
		if($web_cid){
			$where_type=" and id in(".implode(',',$web_cid).")";
		}
		$wap_canshu='&code='.$bankuai_code;
	}
	else{
		$bankuai_title='全部商品';
		$wap_canshu='';
	}
	if($webset['wap']['status']==1 && is_mobile()==1){
		$url=wap_l('goods','index').$wap_canshu;
		jump($url);
	}
	$url_arr=array('code'=>$bankuai_code,'q'=>$_GET['q']);
	if($_GET['do']!=''){
		$url_arr['do']=$_GET['do'];
	}
	
	$goods_type=$duoduo->select_all("type","id,title","tag='goods'".$where_type." order by sort=0 asc,sort asc,id desc");
	foreach($goods_type as $k=>$vo){
		$canshu=array();
		if($bankuai_code){
			$canshu['code']=$bankuai_code;
		}
		$canshu['cid']=$vo['id'];
		if($_GET['do']){
			$canshu['do']=$_GET['do'];
		}
		$goods_type[$k]['url']=u('goods','index',$canshu);
	}
	unset($duoduo);
	$parameter['goods_type']=$goods_type;
	$parameter['bankuai_id']=$bankuai_id;
	$parameter['bankuai_tpl']=$bankuai_tpl;
	$parameter['ajax_load_num']=$ajax_load_num;
	$parameter['goods_total']=$goods_total;
	$parameter['bankuai_code']=$bankuai_code;
	$parameter['url_arr']=$url_arr;
	$parameter['bankuai']=$bankuai;
	$parameter['bankuai_title']=$bankuai_title;
	return $parameter;
}

?>
<?php
if(!defined('INDEX')){
	exit('Access Denied');
}
$parameter=act_goods_index2($dd_tpl_data['ajax_load_num']);
extract($parameter);
$q=$_GET['q'];
$bankuai_tpl=$bankuai_tpl?$bankuai_tpl:$dd_tpl_data['bankuai_tpl'];
$sql       = 'select cid, count(cid) as num from ' . BIAOTOU . 'goods  where `code`="' . $bankuai_code . '" GROUP BY cid';
$_cidTotal = $duoduo->sql_to_array($sql);
$cidTotal  = array();
$cidTotalSum = 0;
foreach ((array)$_cidTotal as $__cidTotal) {
	$cidTotalSum += $__cidTotal['num'];
	$cidTotal[$__cidTotal['cid']] = $__cidTotal['num'];
}
unset($__cidTotal, $_cidTotal);
$yugao_time=date('Y-m-d '.$bankuai['yugao_time'].":00");
if(strtotime($yugao_time)>TIME){
	$yugao_close=true;
}
if($bankuai['huodong_time']){
	$bankuai['huodong_etime']=strtotime(date('Y-m-d '.$bankuai['huodong_time'].":00:00",TIME))+24*3600;
}
$phone_app_status=$app_status;
$css[]=TPLURL."/goods/".$bankuai_tpl."/css/list.css";
$css[]=TPLURL."/goods/inc/css/daohang.css";
?>
<?php include(TPLPATH.'/inc/header.tpl.php');?>
<script type="text/javascript" src="js/scrollpagination.js"></script>
<?php if($bankuai['bg_color']!='' && $bankuai['bg_color']!='none'){?>
<style>
body {background:<?=$bankuai['bg_color']?>;}
</style>
<?php }?>
<?php if($dd_tpl_data['index_ss']==1){?>

<div class="fx_search_bg">
	<div class="fx_search_main width1200">
        <div class="fx_search" id="www_search_id">
		<form action="index.php" amethod="get" class="t_frombox">
        	<div class="search_bg" id="header_serch_left"  onfocusout="if(jQuery('#allMerchants').html()==''){this.className='search_bg';};">
            	<div class="search_text_bg">
                	<span class="search_icon"></span>
                	
					<input type="hidden" id="mod" name="mod" value="goods" class="mod" />
					<input type="hidden" id="act" name="act" value="index" class="act" />
					<input type="hidden" id="act" name="code" value="quan" class="code" />
					<input id=s-txt class="search_text color_99" type="text" placeholder="输入任意优惠券关键词购物拿返利！" onfocus="if(this.value=='输入任意优惠券关键词购物拿返利')this.value='';" onblur="if(this.value=='')this.value='输入任意优惠券关键词购物拿返利';" autocomplete="off" name="q" />
                </div>
                <div class="search_botton"><input name="" type="submit" id="wwwSearchAll" class="botton" value="搜优惠券"></div>
            </div>
       </form>
        <input type="hidden" id="merchUrl" value=""/>
        </div>
        <a href="<?=u('help','taobao')?>" target="_blank"><div class="fx_new_head"></div></a>
    </div>
</div>
<?php }?>	

<?php if(empty($bankuai_code)||$bankuai['fenlei']==1||$bankuai['yugao']==1){?>
<div id="ddlanmu" style=" width:100%">
<div class="jy_tl" id="fl">
            <div class="jy_auto">
              <?php if($goods_type||$first_bankuai['yugao']==1){?>
              <div class="jy_nav" id="<?=$first_bankuai['code']?>_nav"> 
               <?php 
		if(($bankuai['fenlei']==1 || $_GET['code']=='')&&$goods_type){
		$url_canshu=array("code"=>$bankuai_code);
		if($_GET['do']!=''){
			$url_canshu['cid']=0;
			$url_canshu['do']=$_GET['do'];
		}
		?>
              <div class="up_fenlei">
            	<a <?php if(empty($_GET['cid'])){?>class="cur"<?php }?> href="<?=u('goods','index',$url_canshu)?>#fl"></a>
                <?php foreach($goods_type as $vo){?>
<a href="<?=$vo['url']?>#fl" <?php if($_GET['cid']==$vo['id']){?>class="cur c_border"<?php }?>><?=$vo['title']?></a>
          <?php }?> 
		  
		  </div>
                <?php }?>  
				<div style="float:right">
				<a>排序：</a>
				 	  <a class="<?php if($_GET['do']==''){?>cur<?php }?> c_border" href="<?=l('so','index',array('code'=>$_GET['code'],'q'=>$_GET['q']))?>#fl">最新↓</a>
         <a class="<?php if($_GET['do']=='sell_desc'){?>cur<?php }?> c_border" href="<?=l('so','index',array('code'=>$_GET['code'],'keyword'=>$_GET['keyword'],'q'=>$_GET['q'],'do'=>'sell_desc'))?>#fl">最热↓</a>
         <a class="<?php if($_GET['do']=='quan'){?>cur<?php }?> c_border" href="<?=l('so','index',array('code'=>$_GET['code'],'keyword'=>$_GET['keyword'],'q'=>$_GET['q'],'do'=>'quan'))?>#fl">优惠券最多↓</a>
		   <?php if($bankuai['yugao']==1){?>
         <div style="float:right;">
         <?php if($_GET['do']=='yugao'){?>
         <a class="cur2 c_border" href="<?=l('goods','index',array('code'=>$_GET['code']))?>">返回列表</a>
         <?php }else{?>
         <a class="cur2 c_border" <?php if($yugao_close){?>onClick="alert('对不起，亲！<?=$bankuai['yugao_time']?>后公布预告商品。');"<?php }else{?>href="<?=u('goods','index',array('code'=>$bankuai['code'],'do'=>'yugao'))?>"<?php }?> style="cursor:pointer"><span class="yg">明日预告</span></a>
         <?php }?>
         </div>
          <?php }?>      
                </div>
              </div>
              <?php }?>
            </div>
          </div>
		  </div>
<?php }?>

<div style=" height:0px; overflow:hidden">&nbsp;</div>
<div class="goods_list" style="min-height:400px">
  <?php include(TPLPATH."/goods/".$bankuai_tpl."/list.tpl.php");?>
</div>
<div style="clear:both;"></div>
<div id="ajax_goods_loading" style="margin-bottom:10px"><img src="<?=TPLURL?>/inc/images/white-ajax-loader.gif" style="margin-bottom:-2px" alt="加载商品" />&nbsp;&nbsp;正在加载商品</div>
<div class="megas512" style="padding:10px; display:none">
  <?php if($goods_total==1){?>
  <?=pageft($total,$pagesize*(1+$ajax_load_num),'/index.php?mod=so&act=index&code='.$_GET['code'].'&q='.$_GET['q'].'')?>
  <?php }?>
</div>
<?php include(TPLPATH.'/goods/jumpbox.tpl.php');?>
<?php
$a=$url_arr;
$a['do']=trim($_GET['do']);
unset($a['code']);
$contentData=json_encode($a);
?>
<script type="text/javascript">
scrollPaginationPage=(<?=$ajax_load_num?>-1)*<?=($page-1)?>+1;
$(function(){
	LazyLoad($('.list-good'));
	<?php if($ajax_stop!=1 && $ajax_load_num>0){?>
	ajaxLoad('.goods_list .goods_items','.megas512',<?=$ajax_load_num?>,'<?=CURURL.'/?mod=goods&act=data&code='.$_GET['code']?>',<?=$contentData?>,500,LazyLoad);
	<?php }else{?>
	$('.megas512').show();
	<?php }?>
	fixDiv('#ddlanmu',0);
})
countDown('.count_down');
</script>

<div class="quso" style="margin-top:20px">没有找到满意的商品？去淘宝搜索"<font color="#0033FF"><?=$q?></font>" <span><a target="_blank" href="<?=u('jump','s8',array('name'=>''.$q.''))?>" target="_blank">立即去淘宝</a></span></div>
<?php 
include(TPLPATH."/inc/footer.tpl.php");
?>